package com.example.edits;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.viewModel.ApplicationComponent;
import com.example.viewModel.DaggerApplicationComponent;
import com.example.viewModel.MyViewModel;

import javax.inject.Inject;

public class InjectActivity extends AppCompatActivity {

    Button btn1;
    EditText edt1;

    @Inject
    MyViewModel myViewModel;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inject);

        //4.执行注入动作
        ApplicationComponent applicationComponent = DaggerApplicationComponent.create();
        applicationComponent.inject(this);


        btn1 = findViewById(R.id.inject_btn1);
        edt1 = findViewById(R.id.inject_edt1);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myViewModel.updateEdt1("hello world");
                edt1.setText("hello world!");
            }
        });

    }
}
